# -*- coding: utf-8 -*-
import urllib, urllib2
import sys
import json
import sys;
reload(sys);
sys.setdefaultencoding("utf8")

def result(queryStr,userid):
    loginUrl = 'http://www.tuling123.com/openapi/api'
    key = '*****************************'#此处修改为自己的APIKey
    postdata = urllib.urlencode({
        'key': key,
        'info': queryStr,
        'userid': userid
    })
    req = urllib2.Request(url=loginUrl,data=postdata)
    result = urllib2.urlopen(req).read()
    hjson = json.loads(result)
    print  hjson
    code = hjson['code']
    if code == 100000:
        recontent = hjson['text']
    elif code == 200000:
        recontent = hjson['text'] + hjson['url']
    elif code == 302000:
        recontent = hjson['text'] + hjson['list'][0]['info'] + hjson['list'][0]['detailurl']
    elif code == 308000:
        recontent = hjson['text'] + hjson['list'][0]['info'] + hjson['list'][0]['detailurl']
    else:
        recontent = '这个消息人类不能回答，额。。。对了，我不是人类，也不能识别。。。很尴尬'
    return recontent

